<template>
	<view>

		<!-- <cc-defineCateList :data="data" v-if="data.length>0" @itemClick="cateItemClick"></cc-defineCateList> -->
		<view class="neirong">
			<view class="" @click="chufa">
				<u-input placeholder="请选择内容" border="surround" :value="servicename" clearable disabled></u-input>
			</view>

			<button size="mini" type="text" @click="confirmservice">确认服务类别</button>
		</view>

		<u-picker :show="show" :columns="columns" @confirm="confirm" @close="closepicker"
			@cancel="closepicker"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 列表数组 navtitle:标题 shop:展示列表
				columns: [
					// ['中国', '美国', '日本']
				],
				show: false,
				servicename: "",
				valueData: []
			}
		},
		onShow() {
			// this.getfl()
		},
		onLoad() {
			this.getfl()
			this.getService()
		},
		methods: {
			getService() {
				this.$http.post('/employeesAndService/getService', {
					userId: JSON.parse(uni.getStorageSync('userinfo')).id
				}).then(res => {
					console.log('res', res);
					this.servicename = res.result.flName
				})
			},
			chufa() {
				// console.log("确认");
				this.show = true
			},
			closepicker() {
				this.show = false
			},
			confirm(e) {
				console.log("确认", e.value[0]);
				// e.value
				this.servicename = e.value[0]
				this.show = false
			},
			confirmservice() {
				console.log("servicename", this.servicename);
				console.log("信息", this.findValueByLabel(this.servicename));
				console.log("useirhn", JSON.parse(uni.getStorageSync('userinfo')).id);
				this.$http.post('/employeesAndService/insert', {
					userId: JSON.parse(uni.getStorageSync('userinfo')).id,
					serviceId: this.findValueByLabel(this.servicename)
				}).then(res => {
					console.log('res', res);
					uni.showToast({
						title: '设置成功',
						icon: "none"
					});
					this.getService()
				})
			},
			cateItemClick(item) {
				console.log(JSON.parse(item));

				// uni.showModal({
				// 	title: '点击条目',
				// 	content: '点击条目数据 = ' + JSON.stringify(item)
				// })

			},
			findValueByLabel(label) {
				console.log(this.valueData);
				const item = this.valueData.find(item => item.label === label); // 使用 find 查找匹配的项
				return item ? item.value : null; // 如果找到，返回 value，否则返回 null
			},
			getfl(e) {
				this.$http.get('/serviceClassification/serviceChild').then(res => {
					// console.log('res', res.result);
					const dataa = res.result

					const labels = dataa.map(item => item.label); // 使用 map 提取所有的 label
					this.valueData = dataa // 使用 map 提取所有的 label
					// console.log("this", this.valueData);
					this.columns.push(labels)
					// console.log(labels);
				})
				// this.$http.post('/serviceClassification/paginmdQueryfl2', e).then(res => {
				// 	console.log('res', res.result);
				// 	// this.fllistA = res.result.records
				// 	// this.data = res.result.records
				// 	// const targetArray = ["1908155490287222786"]

				// 	// const aa = ["1908156096062160898"]
				// 	// const aak = this.data.map(item => {
				// 	// 	return {
				// 	// 		...item.map(res => {
				// 	// 			return {
				// 	// 				...res,
				// 	// 				flag: aa.includes(item.id)
				// 	// 			}
				// 	// 		})
				// 	// 	}
				// 	// })
				// 	// console.log(aak);
				// 	this.data = res.result


				// })
			},
		}
	}
</script>

<style lang="less">
	.neirong {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
</style>